package test.test.one.levels;

import test.test.one.objects.tools.Speed;
import android.app.Activity;
import android.content.Context;
import android.graphics.Canvas;
import android.util.Log;
import android.view.MotionEvent;
import android.view.SurfaceHolder;

//TODO fix or delete
public class level2 extends AbstractLevel implements SurfaceHolder.Callback {
	
	/*
	 * first is ALWAYS TAG
	 */
	
	private static final String TAG = level2.class.getSimpleName();
	
	/*
	 * variable declaration
	 */
	
	public level2(Context context){
		super(context);
		
		//this.thread=new MainThread(getHolder(), this);
		
		Log.d(TAG, "lvl2 created");
	}
	
	public boolean onTouchEvent(MotionEvent event){
		if (event.getAction() == MotionEvent.ACTION_DOWN) {
			
			//handle all objects
			player.handleActionDown((int)event.getX(), (int)event.getY());
			bt_exit.handleActionDown((int)event.getX(), (int)event.getY());
			
			//end game
			if (bt_exit.isTouched()){
				thread.setRunning(false);
				((Activity)getContext()).finish();
			}
			else{
				Log.d(TAG, "x=" + event.getX() + ",y=" + event.getY());
				new_pos=event.getX();
				player.setSpeed(new Speed(3,0));
				
				if(new_pos<player.getX()){
					player.getSpeed().toggleXDirection();
				}
			}
		}
		return true;
	}
	
	public void render(Canvas canvas) {

		canvas.drawBitmap(background,0,0,null);		
		bt_exit.draw(canvas);
		bag.draw(canvas);
		player.draw(canvas);
	}
	
	public void update() {
		
		if(player.getX()<new_pos+3 && player.getX()>new_pos-3){
			player.setSpeed(new Speed());
		}
		player.update(System.currentTimeMillis(), new_pos);
	
	}


}
